
package com.uuah.server.config.spring.parsers.generic;


import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;

import com.uuah.server.util.spring.SpringXMLUtils;

/**
 * A parser for direct children of the <uuah> element.
 */
public class UuahOrphanDefinitionParser extends OrphanDefinitionParser
{

    public UuahOrphanDefinitionParser(boolean singleton)
    {
        super(singleton);
    }

    public UuahOrphanDefinitionParser(Class beanClass, boolean singleton)
    {
        super(beanClass, singleton);
    }

    protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext)
    {
        assertUuahParent(element);
        return super.parseInternal(element, parserContext);
    }

    protected void assertUuahParent(Element element)
    {
        if (!isTopLevel(element))
        {
            throw new IllegalStateException("This element should be embedded inside the Uuah <"
                    + ROOT_ELEMENT + "> element: " + SpringXMLUtils.elementToString(element));
        }
    }

}
